Attachment name in Outlook is ok, see on Exchange always named "body"

Hi,

I'm using the SMTP adapter to send emails in my organization.

Last week a guy come to talk to me, because the file attached to the email sent to biztalk (2006 R2) has different names when looking from Outlook and when looking from the webmail (Exchange). It seems that this is important to the organization.

I've searched in this forums, and get some information, but none of that information found solve my issue.

This is how i'm setting the file name:

Message(FILE.ReceiveFileName) = "test.txt";

Message(MIME.FileName) = "test.txt";

Does anyone get this "error"? Any suggestions to solve this?

Thanks in a

October 14th, 2013 5:11pm

Hi Bessa,

Looks like you use Orchestrations message assignment shape, so you can you try this for file name in attachment:

Message.Attachment(MIME.FileName) = "Test.txt";

Refer this article for more info..

If you want to try setting the attachment in message only scenario (without orchestration), you can do so using a custom pipeline and follow this reference.

Free Windows Admin Tool Kit Click here and download it now
October 14th, 2013 5:20pm

Thanks for the reply!

I need to user orchestration because of our business rules.

The message that I'm sending is a XMLDocument... doesn't have that attribute..

October 14th, 2013 5:29pm

Hope you would have defined a multipart message. And the attachment you have sending is the body-part of your message. To set the name to the email attachment, you have to set the attachment parts MIME.FileName. So for example if your message name is Message (which is of multi-part type), while definiing the multpl-part, if identifer for multi-part message is set as Attachment, then you have to set

Message.Attachment(MIME.FileName)

So for your case, you have replace the word Attachment the relevant bodypart name of your message.Attachment is the identifier for multi-part message. Following is the property of the my multi-part message type in Orchestration view. Give the relavant identifier name in Message.YourMultiPartMessageBodyPartID(MIME.FileName).

Note: I used BodyPart as attachment, give the relevant part you have used for attac

Free Windows Admin Tool Kit Click here and download it now
October 14th, 2013 6:01pm

I'll try to change the orchestration, and make the changes you suggest. I'll let you know the result as soon as I finish that.

Thanks

October 14th, 2013 6:05pm

Thought you already have some orchestration from where you 're already sending email with attachment...

Anyway, refer these articles for help..

Sending SMTP email from within BizTalk Orchestration

http://biztalktalk.wordpress.com/2008/08/28/sending-attachments-through-a-dynamic-send-port/

Free Windows Admin Tool Kit Click here and download it now
October 14th, 2013 6:15pm

Hi,

Yes, I do have an orchestration, what I don't have is a multipart message. I only have a XMLDocument message. 

I'm already sending emails throw my orchestration, my only error is when watching via webmail (exchange webmail) the name appears "body.txt"; if I see the exactly same message in Outlook program I see the real name of the file (the name that I gave before).

So, my problem is not sending email.

October 14th, 2013 6:18pm

That's Ok, You can try the steps as mentioned above..
Free Windows Admin Tool Kit Click here and download it now
October 14th, 2013 6:25pm

Hi!

I've tried that solution, but same result!

File name good in Outlook; NOT GOD in webmail (Outlook 365; exchange server)

Any other guess? 

October 14th, 2013 8:25pm

Please create pipeline component for giving file as per your requirement as shown below code in execute method of IComponent interface:

 string filename = (string)pInMsg.Context.Read("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties");
                        int lastindex = filename.LastIndexOf(@"\");
                        filename = filename.Substring(lastindex + 1);
                        bodyPart.PartProperties.Write("FileName", "http://schemas.microsoft.com/BizTalk/2003/mime-properties", filename);


                        IBaseMessageFactory messageFactory = pContext.GetMessageFactory();

                        IBaseMessage newMessage = messageFactory.CreateMessage();

                        newMessage.Context = pInMsg.Context;

                        //creating new part

                        IBaseMessagePart attachmentPart = messageFactory.CreateMessagePart();

                        attachmentPart.Data = pInMsg.BodyPart.Data;

                        attachmentPart.Charset = pInMsg.BodyPart.Charset;

                        attachmentPart.ContentType = pInMsg.BodyPart.ContentType;

                        newMessage.AddPart(pInMsg.BodyPartName,pInMsg.BodyPart, false);

                        newMessage.AddPart("Attachment",attachmentPart, true); 

And after that Make sure that you r adding your custom pipeline component after MIME Encoder component in Encode stage of send pipeline. I hope this will help. Add both components in same stage but first add MIME Encoder and then your custom pipeline component.

Free Windows Admin Tool Kit Click here and download it now
October 15th, 2013 3:07pm

Hi,

Unfortunately, I could only test this solution today. I've created the new pipeline and tested.

1) Using the MIME Encoder the file arrive as part of the email, not a file attached

2) without using MIME Encoder I got two files: one corrected (file name and content Ok); and other one with body.

Already try to change pipeline to remove the "body" file, but I'm not finding any way..

Any other suggestion?

Thanks in advance,

January 6th, 2014 9:22pm

Sending a BizTalk Message as an e-mail you have two options

  1. In case you want to send the message as an attachment & want to use the MIME Encoder then there is an option to do this (refer http://msdn.microsoft.com/en-us/library/aa561432.aspx)
  2. You want to send the BizTalk Message as the body of the e-mail in which case the property should be set to false.

Send body part as attachment

Set to True if you want to send the body party of a BizTalk message as a MIME attachment.

Default value: False

ImportantImportant
You should not set this property to True when sending messages between BizTalk Servers. Otherwise, the message decoding will require custom coding because the message is interpreted on the receive side as a two-part message.

In case you send the BizTalk message as attachment, then the MIME encoder will generate a filename of it own which it will assign as MessagePart property (MIME.FileName). You may create a custom component that runs after the MIME Encoder and overwrite this with a different one (if you know it).

When this message it read, the attachment filename will be what is generated by the MIME Encoder (if not overwritten).

The default contents of an e-mail are always "body" and you should not change that. Most of the e-mail readers will render the contents of this and NOT SHOW THIS AS AN ATTACHMENT.

Regards.

Free Windows Admin Tool Kit Click here and download it now
January 7th, 2014 1:34pm

Hi,

Thanks for the good explanation that you provide. Actually I did not change the property "Send body as attachement" and that's why the content of the file was directly in email body.

However, I have exactly the same issue. The filename that appear in "office 365" webmail is "body.txt" instead of what I have in outlook.

Here are 2 images that show how I get the files in both systems (office 365 - in owa error is equal; and outlook)

Office 365:

Office 365

Outlook:

Outlook

What am I asking is impossible? Or am I missing something really simple?

Thanks in advance

January 7th, 2014 3:27pm

The reason you're getting the name of the attachment as "body.txt" is because as you said, the message is in the body and in sending that the content-type was set as text/xml. It is possible that Office 365 does not render such content and thus treats it as an attachment (calling it body because e-mail have to have a body).

To further experiment, you can create a multi-part message in BizTalk, one part called "body" (marked as body) and another part as attachment (with the XML Schema of your BizTalk Message). After having constructed the message ensure that the MIME.FileName is assigned to the attachment part with a name "ATTACHMENT.XML", set the content-type = "text/xml". For the body message part set the content-type to text/html.

Send this message (no MIME encoding) using SMTP to the e-mail addresses. You should be able to see the attachment with the name properly in either readers then.

Regards.

Free Windows Admin Tool Kit Click here and download it now
January 7th, 2014 5:31pm

I have done the changes that you said, but, the result was 2 files.

1) my file 

2) the body..

this appears in both readers (outlook and office 365).

I do understand that email needs to have a body, but my email has a body (marked with yellow in image). I can't "delete" / hide the file body that have in attach?

Right now, I'm not using any pipeline, just send directly do SMTP adapter..

my code in construction message:

msgEnvelope.Body = ""; //body has a string type (and marked as Message Body Part = true)
msgEnvelope.Body(Microsoft.XLANGs.BaseTypes.ContentType) = "text/html";

// Set the Filename of the attachment
msgEnvelope.Attachment = Message_In; //attachment has a XMLDocumentType (result needs to be inserted in a txt file)
msgEnvelope.Attachment (MIME.FileName) ="UmNome.txt";
msgEnvelope.Attachment(Microsoft.XLANGs.BaseTypes.ContentType) = "text/plain";

Also tried to force to have only 1 attachment, but no success as well
msgEnvelope(SMTP.MessagePartsAttachments) = 1;

 

January 7th, 2014 7:42pm

What I had done was

Create a Multi-part Message with two parts, 1 (marked as body) of type "RawStringFormat" and the second of type "RawString".

The reason for using RawString was because string is still converted into XML as <string></string> on output. So when I assigned HTML it still came with the base tags causing the e-mail readers to not understand and render it correctly. The RawString Formatter (BizTalk SDK Samples) ensured that content were sent as is.

In the message construct shape I had the code as below

// This is where we construct the "body" part of the message
MessageBody = "<HTML>...... your message body ...... </HTML>";
MyMultiPartMessage.BodyPart = new Microsoft.Samples.BizTalk.XlangCustomFormatters.RawString(UnparsedMessageAlertBody);
MyMultiPartMessage.BodyType(Microsoft.XLANGs.BaseTypes.ContentType) = "text/html";
//
// Handle the attachment
XMLAttachment = new System.Xml.XmlDocument();
XMLAttachment = MyBizTalkMessage;
AttachmentAsText = XMLAttachment.OuterXml;
MyMultiPartMessage.Attachment = new Microsoft.Samples.BizTalk.XlangCustomFormatters.RawString(AttachmentAsText);
MyMultiPartMessage.Attachment(Microsoft.XLANGs.BaseTypes.ContentType) = "text/plain";
MyMultiPartMessage.Attachment(MIME.FileName) = "Whatever Filename you want".txt;
//
// Set the Message Subject
MyMultiPartMessage(SMTP.Subject) = "Whatever subject you want";
//
// Set the message SMTP Properties
MyMultiPartMessage(SMTP.EmailBodyFileCharset) = "UTF-8";
MyMultiPartMessage(SMTP.MessagePartsAttachments) = 2;
MyMultiPartMessage(SMTP.From) = <sender address>;
MyMultiPartMessage(SMTP.SMTPHost) = <your relay or smart host>;
MyMultiPartMessage(SMTP.SMTPAuthenticate) = 0;
MyMultiPartMessage(SMTP.DeliveryReceipt) = false;
MyMultiPartMessage(SMTP.ReadReceipt) = false;
//
// Dynamic Ports requirements
MessageTransmissionPort(Microsoft.XLANGs.BaseTypes.Address) = <destination e-mail address>;
MessageTransmissionPort(Microsoft.XLANGs.BaseTypes.TransportType) = "SMTP";

The result message did not result in any additonal body (both in Outlook and OWA [which is the closest I got to Office 365]). You may try playing around with the "Attachment" Content-Type as appropriate.

Regards.

  • Marked as answer by Bessa Wednesday, January 08, 2014 11:44 AM
Free Windows Admin Tool Kit Click here and download it now
January 8th, 2014 7:57am

Tried what you said it worked perfectly!

The main difference from my code to your was that I was using the SMTP adapter, directly in send port! In this sample, you are using a dynamic port and fill all necessary data to adapter, in the construction of the message.

Any known reason to not use SMTP adapter directly for this issues?

Thanks

January 8th, 2014 2:44pm

I liked the flexibility the Dynamic Port provides. That way I can define one Dynamic Port and use it across multiple orchestrations (usually for Dynamic Ports, the deployment of the orchetsration creates its own port. I usually change the binding to the one I create and delete the auto-crated one.)

Also with a fixed port, I could not find a way to assign different destination addresses for different messages. If you will always send the mail to the same e-mail address, the static configured SMTP would work for you too (you would not need the last two lines in the code).

Regards.

Free Windows Admin Tool Kit Click here and download it now
January 8th, 2014 5:20pm

Strange (or not) if I take off the last 2 lines (Dynamic Port definition) and call the SMTP adapter directly I get the error that I previous had, 2 files (body; and my file). But, after this first test I changed a configuration in SMTP adapter, just changed the "Email body properties" in  "Compose" tab to "Biztalk message body part" (previous I had text, but with all this talk I understood better this property). 

In my case, is always the same destination address and same text, just the attached files changes. That's why I was using SMTP adapter directly.. .Well, now I have a solution. Better than that, I can choose the way! :)

Thanks again for the time spent!

Best regards,

January 8th, 2014 7:13pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics